package logic

import (
	"bilibili/bilibilirpc/bilibilirpc"
	"bilibili/bilibilirpc/internal/svc"
	"bilibili/models/mysql"
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
)

type RealnameLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRealnameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealnameLogic {
	return &RealnameLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RealnameLogic) Realname(in *bilibilirpc.RealnameRequest) (*bilibilirpc.RealnameResponse, error) {
	// todo: add your logic here and delete this line

	realname := mysql.UserRealname{
		Name:   in.Name,
		Idcard: in.IdCard,
		Status: "已认证",
	}
	err := mysql.DB.Debug().Create(&realname).Error
	if err != nil {
		return nil, fmt.Errorf("实名认证错误")
	}
	return &bilibilirpc.RealnameResponse{
		Id: int64(realname.ID),
	}, nil
}
